package game.gamescene
{
	import Box2D.Dynamics.b2Body;
	
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.utils.getDefinitionByName;
	
	public class GameItem extends Sprite
	{
		protected var _data:XML;
		public var phBody:b2Body;

		public var distance:Number = 0.0; // 0 -> 1.0
		public var xFactor:Number = 0.0; // 0 -> 1.0
		
		public function GameItem( d:XML )
		{
			super();
			
			_data = d;
						
			var mv:MovieClip = Ref.view.assetsFactory.getElement(_data.@id) as MovieClip; 
			mv.x = mv.y = 0.0;
			addChild(mv);
		} 
		
		public function get data():XML { return _data; }
		public function set data( val:XML ):void { _data = val; }

		public function setPositionAndDistance( val:Number ):void
		{
			distance = val;	
			
			alpha = alphaFunc();
			
			positionFunc();
		}
		
		protected function alphaFunc():Number
		{
			return Math.min ( 1.0, 1.0/.1*(distance - 0.1) + 1.0 );
		}
		
		protected function positionFunc():void
		{
			y = GameScene.SCENE_CENTER_Y  + (GameScene.SCENE_CORRIDOR_HEIGHT - 100 ) *distance;
			
			var b:Number =  ( GameScene.SCENE_CORRIDOR_BASE )*xFactor;
			x = GameScene.SCENE_CENTER_X + b*distance;
			
			scaleX = scaleY = distance*.9;
		}
	}
}